#include <windows.h>
#include <string>
using namespace std;

#ifndef __UsbCdcDevice_h_
#define __UsbCdcDevice_h_

#define USB_DCD_MSG_INIT			WM_USER + 1
#define USB_DCD_MSG_UPDATE          WM_USER + 10
#define USB_DCD_MSG_CENTER          WM_USER + 11
#define USB_DCD_MSG_LEFT			WM_USER + 12
#define USB_DCD_MSG_RIGHT			WM_USER + 13
#define USB_DCD_MSG_EXIT            WM_USER + 99

class UsbCdcDeviceC
{
public:
	static UsbCdcDeviceC* instance();
	void init();
	~UsbCdcDeviceC();
	void close();
	bool isDeviceAttachedGet();
	bool postMessage(UINT message);

private:
	UINT m_timer;
	HANDLE m_thread;
	DWORD m_threadId;
	string m_comPort;
	HANDLE m_comPortHandle;
private:
	UsbCdcDeviceC();
	string checkIfPresentAndGetCOMString(string DeviceIDString);
	void comPortSet(string);
	string comPortGet();
	//message processing thread
	static DWORD WINAPI usbCdcDeviceThreadTask(LPVOID lpParam);
	static void onTimer(HWND hwnd, UINT uMsg, UINT idEvent,DWORD dwTime);
	string toLower(string str);
	BOOL serialWrite(char* lpBuf, DWORD dwToWrite);
};

#endif __UsbCdcDevice_h_